//
//  CIDetector-QRCode.m
//  CoreImageDemo
//
//  Created by zero on 2017/6/13.
//  Copyright © 2017年 zero. All rights reserved.
//

#import "CIDetector-QRCode.h"

@interface CIDetector_QRCode ()
@property (nonatomic,strong) UIImageView* imageView;
@property (nonatomic,strong) UIImage* image;
@end

@implementation CIDetector_QRCode

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor whiteColor];
    self.image = [UIImage imageNamed:@"1497318348"];
    [self.view addSubview:self.imageView];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self action_recognitionQRCode];
}

- (void)action_recognitionQRCode{
    CIImage* image = [CIImage imageWithCGImage:self.image.CGImage];
    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:nil];
    NSArray* result = [detector featuresInImage:image];
    for (CIQRCodeFeature* feature in result) {
        NSLog(@"%@",feature.messageString);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIImageView*)imageView{
    if(!_imageView){
        //        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)/2.0)];
        //        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView = [[UIImageView alloc]initWithImage:self.image];
        _imageView.frame = CGRectMake(0, 0, self.image.size.width, self.image.size.height);
    }
    return _imageView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
